package com.wolfpire.pages.controller;

import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wolfpire.chapter.service.ChapterService;
import com.wolfpire.news.service.NewService;
import com.wolfpire.notice.service.NoticeService;
import com.wolfpire.section.service.MyDownLoadHistoryService;
import com.wolfpire.section.service.SectionService;
import com.wolfpire.section.service.StudyHistoryService;
import com.wolfpire.subject.service.SubjectService;
import com.wolfpire.system.common.Constants;
import com.wolfpire.system.common.EasyuiPage;
import com.wolfpire.system.common.EasyuiPagination;
import com.wolfpire.system.common.MD5;
import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.Result;
import com.wolfpire.system.common.springmvc.PrincipalArgument;
import com.wolfpire.system.model.Attachment;
import com.wolfpire.system.model.Chapter;
import com.wolfpire.system.model.MyDownLoadHistory;
import com.wolfpire.system.model.New;
import com.wolfpire.system.model.Notice;
import com.wolfpire.system.model.Profession;
import com.wolfpire.system.model.Section;
import com.wolfpire.system.model.StudyHistory;
import com.wolfpire.system.model.Subject;
import com.wolfpire.system.model.User;
import com.wolfpire.system.model.UserGroup;
import com.wolfpire.system.service.AttachmentService;
import com.wolfpire.system.service.UserGroupService;
import com.wolfpire.system.service.UserService;
import com.wolfpire.system.service.impl.UserServiceImpl;

@Controller
@RequestMapping("/pages")
public class PagesController {
	
	@Resource private NoticeService noticeService;
	@Resource private SubjectService subjectService;
	@Resource private NewService newService;
	@Resource private SectionService sectionService;
	@Resource private AttachmentService attachmentService;
	@Resource private UserService userService;
	@Resource private UserGroupService userGroupService;
	@Resource private StudyHistoryService studyHistoryService;
	@Resource private ChapterService chapterService;
	@Resource private MyDownLoadHistoryService myDownLoadHistoryService;
	
	/**
	 * 首页中的公告消息
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/notice")
	public List<Notice> NoitceInfoControl(HttpServletRequest request , HttpServletResponse response){	
		List<Notice> notices = this.noticeService.list(8);
		//Notice notice = this.noticeService.currentNotice(Long.valueOf(2), "学院公告");
		//List<Map<String, Object>> list = this.sectionService.getBySubjcetId(22);
		//List<Attachment> a = this.attachmentService.getByBiz(Long.valueOf(5), "section");
		//System.out.println(a);
		return notices;
	}
	
	@ResponseBody
	@RequestMapping("/currentNotice")
	public Notice CurrentNotice(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		String type = request.getParameter("adType");
		Notice notice = this.noticeService.currentNotice(Long.valueOf(id), type);
		return notice;
	}
	
	/**
	 * 当前公告的上一条公告
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/frontNotice")
	public Notice FrontNotice(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		String type = request.getParameter("adType");
		Notice notice = this.noticeService.findFrontNotice(Long.valueOf(id), type);
		return notice;
	}
	/**
	 * 当前公告的下一条公告
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/nextNotice")
	public Notice NextNotice(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		String type = request.getParameter("adType");
		Notice notice = this.noticeService.findNextNoitce(Long.valueOf(id), type);
		return notice;
	}
	/**
	 * 首页中的新闻资讯
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/new")
	public List<New> NewInfoControl(HttpServletRequest request , HttpServletResponse response){	
		List<New> news = this.newService.list(8);
		//Notice notice = this.noticeService.currentNotice(Long.valueOf(2), "学院公告");
		return news;
	}
	/**
	 * 当前新闻资讯
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/currentNew")
	public New CurrentNew(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		New newInfo = this.newService.currentNew(Long.valueOf(id));
		return newInfo;
	}
	
	/**
	 * 当前新闻资讯的上一条公告
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/frontNew")
	public New FrontNew(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		New newInfo = this.newService.findFrontNew(Long.valueOf(id));
		return newInfo;
	}
	/**
	 * 当前新闻资讯的下一条公告
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/nextNew")
	public New NextNew(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		New newInfo = this.newService.findNextNew(Long.valueOf(id));
		return newInfo;
	}
	
	/**
	 * 首页新开课程
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/subjects")
	public List<Subject> SubjectsControl(HttpServletRequest request , HttpServletResponse response){
		
		List<Subject> subjects = this.subjectService.list(5);
		System.out.println(subjects);
		return subjects;
	}
	/**
	 * 更多新开课程
	 * @param page
	 * @param filterSubject
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/subjectsList")
	public EasyuiPagination<Subject> queryList(EasyuiPage<Subject> page, Subject filterSubject) {
		Page<Subject> subjects = this.subjectService.setPageDataList(page, filterSubject);
		return new EasyuiPagination<Subject>(subjects);
	}
	/**
	 * 更多公告消息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/noticeMoreAction")
	public ModelAndView NoticeMoreAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/ad_list";
		ModelAndView view = new ModelAndView();
		view.getModelMap().put("adType", request.getParameter("adType"));
		view.setViewName(url);
		return view;
	}
	/**
	 * 点击公告消息的动作
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/noticeAction")
	public ModelAndView NoticeAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/ad_article";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("id", request.getParameter("id"));
		view.getModelMap().put("adType", request.getParameter("adType"));
		return view;
	}
	
	@RequestMapping("/subjectMoreAction")
	public ModelAndView SubjectMoreAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/course_list";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	@RequestMapping("/subjectdetail")
	public ModelAndView SubjectDetail(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/course_article";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("id", request.getParameter("id"));
		return view;
	}
	@RequestMapping("/newsMoreAction")
	public ModelAndView NewsMoreAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/news_list";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	@RequestMapping("/newsdetail")
	public ModelAndView NewsDetail(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/news_article";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("id", request.getParameter("id"));
		return view;
	}
	@RequestMapping("/login")
	public ModelAndView UserLogin(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/login";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	
	///更换密码
	@RequestMapping("/changpwd")
	public ModelAndView ChangPassword(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/password";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	
	/**
	 * 点击注册账号链接跳转到注册账号页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/registerView")
	public ModelAndView registerAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/register";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	
	@RequestMapping("/getCode")
	public void getCodeAction(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/register";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
	}
	
	@RequestMapping("/mycourse")
	public ModelAndView MyCourseList(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/course_list";
		String loginUrl = "pages/login";
		ModelAndView view = new ModelAndView();
		if(request.getSession().getAttribute(Constants.SESSION_USER) != null){      //登陆状态
			view.setViewName(url);
			view.getModelMap().put("userid", request.getParameter("userid"));
		}else                                                                       //没登陆
			view.setViewName(loginUrl);
		return view;
	}
	@RequestMapping("/learnhistory")
	public ModelAndView LearnHistory(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/m_history";
		String loginUrl = "pages/login";
		ModelAndView view = new ModelAndView();
		if(request.getSession().getAttribute(Constants.SESSION_USER) != null){      //登陆状态
			view.setViewName(url);
			view.getModelMap().put("userid", request.getParameter("userid"));
		}else                                                                       //没登陆
			view.setViewName(loginUrl);
		return view;
	}
	/**
	 * 根據學科ID獲取章節
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findchaptersection")
	public List<Map<String, Object>> FindChapterSection(HttpServletRequest request , HttpServletResponse response){
		String id = request.getParameter("id");
		User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
		Long userId = null;
		if(user != null)
			userId = user.getId();
		List<Map<String, Object>> list = this.sectionService.getBySubjcetId(userId, Long.valueOf(id));
		return list;
	}
	
	@RequestMapping("/chaptervedio")
	public ModelAndView showVediopage(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/onvedioapp";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("id", request.getParameter("id"));
		view.getModelMap().put("sectionId", request.getParameter("sectionId"));
		return view;
	}
	/**
	 * 根据用户ID查找我的课程
	 * @param userid
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/findMyCourse", method = {RequestMethod.POST, RequestMethod.GET})
	public List<Map<String, Object>> findMyCourse(HttpServletRequest request , HttpServletResponse response) {
		try {
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			List<Map<String, Object>> lists = new ArrayList<Map<String,Object>>();
			List<Subject> subjects = new ArrayList<Subject>();
			/*User user = null;
			if(userId != null && !"".equals(userId)){
				user = this.userService.get(Long.valueOf(userId));
			}*/
			if(user != null && "admin".equals(user.getAccount())){
				subjects = this.subjectService.findAllSubject();
				for(Subject subject:subjects){
					List<Chapter> chapters = this.chapterService.getBySubjectId(subject.getId());
					int i = 0;
					for(Chapter chapter : chapters){
						List<Section> sections = this.sectionService.getByChapterId(chapter.getId());
						i = i+ sections.size();
					}
					String result = String.valueOf(0);
					int percent = this.studyHistoryService.complempercent(subject.getId(), user.getId());
					NumberFormat numberFormat = NumberFormat.getInstance();  
					// 设置精确到小数点后2位  
					numberFormat.setMaximumFractionDigits(0);  
					if(i != 0) 
						result = numberFormat.format((float) percent / (float) i * 100);  
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("id", subject.getId());
					map.put("percent", result);
					map.put("name", subject.getName());
					map.put("remark", subject.getRemark());
					map.put("image", subject.getImage());
					lists.add(map);
				}
			}else{
				List<UserGroup> userGroups = this.userGroupService.findUserGroupByUserId(user.getId());
				for(UserGroup userGroup : userGroups){
					subjects = this.subjectService.findSubjectByUserGroupId(userGroup.getId());
					for(Subject subject:subjects){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("id", subject.getId());
						map.put("name", subject.getName());
						map.put("remark", subject.getRemark());
						map.put("image", subject.getImage());
						lists.add(map);
					}
				}
			}
			return lists;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 根據sectionId獲取視頻資源
	 * @param request
	 * @param response
	 * @return
	 */
	/*@ResponseBody
	@RequestMapping("/findResource")
	public List<Attachment> FindResourceBySection(HttpServletRequest request , HttpServletResponse response){
		String sectionId = request.getParameter("sectionId");   
		List<Attachment> a = this.attachmentService.getByBiz(Long.valueOf(sectionId), "section");
		return a;
	}*/
	/**
	 * 这个用来查找视频资源的
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findResource")
	public List<Map<String, Object>> FindResourceBySection(HttpServletRequest request , HttpServletResponse response){
		String sectionId = request.getParameter("sectionId");   
		List<Map<String, Object>> list = this.sectionService.getBySectionId(Long.valueOf(sectionId),"video");
		return list;
	}
	/**
	 * 获取节的文档资源，讲义或作业等
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findDocResource")
	public List<Map<String, Object>> FindDocBySection(HttpServletRequest request , HttpServletResponse response){
		String sectionId = request.getParameter("sectionId");   
		List<Map<String, Object>> list = this.sectionService.getBySectionId(Long.valueOf(sectionId),"doc");
		return list;
	}
	
	@RequestMapping("/listByAttId")
	public ModelAndView list(@PrincipalArgument User user, @RequestParam Long attId) {
		/*System.out.print(attId);
		String type = null;
		ModelAndView mv = new ModelAndView("pages/onvedioapp");
		String filePath = "";
		if(attId != null){
			Attachment attachment = this.attachmentService.get(attId);
			filePath = "\\atta\\" + attachment.getFilePath();
			type = getFileSuffix(filePath);
		}
		mv.getModelMap().put("filePath", filePath);
		mv.getModelMap().put("type", "video/"+ type);
		return mv;*/
		System.out.print(attId);
		String type = null;
		ModelAndView mv = new ModelAndView("videoManage/video_list");
		String filePath = "";
		if(attId != null){
			Attachment attachment = this.attachmentService.get(attId);
			filePath = "\\atta\\" + attachment.getFilePath();
			type = getFileSuffix(filePath);
		}
		mv.getModelMap().put("filePath", filePath);
		mv.getModelMap().put("type", "video/"+ type);
		return mv;
	}
	
	///app路径
	@RequestMapping("/subjectapp")
	public ModelAndView SubjectMoreActionApp(HttpServletRequest request , HttpServletResponse response) {
		String url = "pages/mycourseapp";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		return view;
	}
	@RequestMapping("/subjectdetailapp")
	public ModelAndView SubjectDetailApp(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/coursedetailapp";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("id", request.getParameter("id"));
		return view;
	}
	//PC端跳转到视频
	@RequestMapping("/onlinecourse")
	public ModelAndView OnineCourse(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/myvideo";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("sectionId", request.getParameter("sectionId"));
		view.getModelMap().put("id", request.getParameter("id"));
		return view;
	}
	
	//获取文件的后缀类型
	public String getFileSuffix(String filePath){ 
		int len = filePath.lastIndexOf('.'); 
		return filePath.substring(len+1,filePath.length());	
	}
	/**
	 * 	修改用户的密码
	 * @param id	用户ID
	 * @param password	用户密码
	 */
	@RequestMapping("/changePwd")
	public void changePassword(Long id, String password){
		this.userService.saveUserPassword(id, password);
	}
	
	@ResponseBody
	@RequestMapping("/changeNewpwd")
	public Map<String, Object> changeNewpwd(HttpServletRequest request , HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean result = false;
		String msg = null;
		String originpwd = request.getParameter("originpwd");
		String newpwd = request.getParameter("newpwd");
		String secondpwd = request.getParameter("secondpwd");
		User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
		try {
			MD5 md5 = new MD5();
			String s = md5.getMD5ofStr(originpwd);
			if(user.getPassword().equals(s)){        //界面如果密码输入都无误 那就执行方法
				this.userService.saveUserPassword(user.getId(), newpwd);
				request.getSession().invalidate();           //清空缓存
				result = true;
				msg = "修改成功";
			}else{
				result = false;
				msg = "原始密码不对";
			}
		}catch (Exception e) {
			e.printStackTrace();
			msg = "保存失败，请联系管理员";
		}
		map.put("result", result);
		map.put("msg", msg);
		return map;
	}
	/**
	 * 注册用户
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/registUser")
	public Map<String, Object> registUser(HttpServletRequest request , HttpServletResponse response) {
		Map<String, Object> map = new HashMap<String, Object>();
		boolean result = false;
		String msg = null;
		String account = request.getParameter("account");
		String pwd1 = request.getParameter("pwd1");
		String email = request.getParameter("email");
		String pwd2 = request.getParameter("pwd2");
		try {
			MD5 md5 = new MD5();
			String s = md5.getMD5ofStr(pwd1);
			this.userService.registUser(account, s, email);
			result = true;
			msg = "注册成功";
		}catch (Exception e) {
			e.printStackTrace();
			msg = "注册失败";
		}
		map.put("result", result);
		map.put("msg", msg);
		return map;
	}
	
	//PC端跳转到视频
	@RequestMapping("/userInfo")
	public ModelAndView UserInfo(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/member_info";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("userid", request.getParameter("userid"));
		return view;
	}
	
	//PC端跳转到我的下载
	@RequestMapping("/myDownload")
	public ModelAndView getMyDownloads(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/member_xz";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("userid", request.getParameter("userid"));
		return view;
	}
	
	//PC端跳转到简介
	@RequestMapping("/aboutInfo")
	public ModelAndView getAboutInfo(HttpServletRequest request , HttpServletResponse response) {

		String url = "pages/member_about";
		ModelAndView view = new ModelAndView();
		view.setViewName(url);
		view.getModelMap().put("userid", request.getParameter("userid"));;
		return view;
	}
		
		/**
		 * 根据用户ID查找用户
		 * @param request
		 * @param response
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/getUser")
		public User getUser(HttpServletRequest request , HttpServletResponse response){
			String userId = request.getParameter("userid");   
			User user = this.userService.get(Long.valueOf(userId));
			return user;
		}
		
		//PC端跳转到修改密码
		@RequestMapping("chageMyPwd")
		public ModelAndView ChangePwd(HttpServletRequest request , HttpServletResponse response) {

			String url = "pages/member_pwd";
			ModelAndView view = new ModelAndView();
			view.setViewName(url);
			view.getModelMap().put("userid", request.getParameter("userid"));
			return view;
		}
		
		/**
		 * 点击节视频记录用户的学习时间
		 * @param request
		 * @param response
		 * @param sectionId	节ID
		 * @param content   评论内容
		 * @param flag      标识位（create end  pinglun）
		 * @param xingxing  点赞星星
		 */
		@RequestMapping("/saveStudyHistory")
		public void SaveStudyHistory(HttpServletRequest request , HttpServletResponse response
				, @RequestParam(value = "sectionId", required = false) long sectionId
				, @RequestParam(value = "content", required = false) String content
				, @RequestParam(value = "flag", required = false) String flag
				, @RequestParam(value = "xingxing", required = false) String xingxing){
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			if(user != null){
				this.studyHistoryService.saveStudyHistory(user.getId(), Long.valueOf(sectionId), flag, content, xingxing);
			}
		}
		
		/**
		 * 点击下载中的附件做记录
		 * @param request
		 * @param response
		 * @param sectionId 节ID
		 * @param filePath  附件的路径
		 */
		@RequestMapping("/saveMyDownLoadHistory")
		public void SaveMyDownLoadHistory(HttpServletRequest request , HttpServletResponse response
				, @RequestParam(value = "sectionId", required = false) long sectionId
				, @RequestParam(value = "filePath", required = false) String filePath){
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			if(user != null){
				this.myDownLoadHistoryService.saveMyDownLoadHistory(user.getId(), sectionId, filePath);
			}
		}
		
		/**
		 * 用户曾经下载过资源的相关学科
		 * @param request
		 * @param response
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/findMyDownLoadSubject")
		public List<MyDownLoadHistory> findMyDownLoadSubject(HttpServletRequest request , HttpServletResponse response){
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			return this.myDownLoadHistoryService.findMySubject(user.getId());
		}
		
		/**
		 * 查找用户下载过的资源
		 * @param request
		 * @param response
		 * @param subjectId 学科ID
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/findMyDownLoadFile")
		public List<MyDownLoadHistory> findMyDownLoadFile(HttpServletRequest request , HttpServletResponse response
				, @RequestParam(value = "subjectId", required = false) long subjectId){
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			return this.myDownLoadHistoryService.findMyDownLoadHistory(user.getId(), subjectId);
		}
		
		/**
		 * 查找用户的学习记录
		 * @param request
		 * @param response
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/findStudyHistory")
		public List<StudyHistory> findStudyHistory(HttpServletRequest request , HttpServletResponse response){
			String date = request.getParameter("date");   
			User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			return this.studyHistoryService.findStudyHistory(user.getId(), date);
		}
		
		/**
		 * 查找用户对某视频的评论
		 * @param request
		 * @param response
		 * @return
		 */
		@ResponseBody
		@RequestMapping("/findPinLunBySection")
		public List<Map<String, Object>> findPinLunBySection(HttpServletRequest request , HttpServletResponse response
				, @RequestParam(value = "sectionId", required = false) long sectionId){   
			//User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
			List<Map<String, Object>> lists = new ArrayList<Map<String,Object>>();
			List<StudyHistory> studyHistorys = this.studyHistoryService.findPinLunBySection(sectionId, "pinglun");
			for(StudyHistory studyHistory : studyHistorys){
				Map<String, Object> studyHistoryMap = new HashMap<String, Object>();
				studyHistoryMap.put("id", studyHistory.getId());
				studyHistoryMap.put("userName", this.userService.get(studyHistory.getUserId()).getAccount());
				studyHistoryMap.put("subjectId", studyHistory.getSubjectId());
				studyHistoryMap.put("sectionId", studyHistory.getSectionId());
				studyHistoryMap.put("subjectName", studyHistory.getSubjectName());
				studyHistoryMap.put("chapterName", studyHistory.getChapterName());
				studyHistoryMap.put("sectionName", studyHistory.getSectionName());
				studyHistoryMap.put("recordTime", studyHistory.getRecordTime().toString());
				System.out.println("hijk===="+studyHistory.getRecordTime());
				studyHistoryMap.put("content", studyHistory.getContent());
				studyHistoryMap.put("xingxing", studyHistory.getXingxing());
				lists.add(studyHistoryMap);
			}
			return lists;
		}

}
